<html>
<head><meta charset="utf-8"><title>Staged queries compiler-team#391 · t-compiler/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/index.html">t-compiler/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html">Staged queries compiler-team#391</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220720924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220720924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220720924">(Dec 22 2020 at 18:42)</a>:</h4>
<p>Creating the topic manually as it didn't happen automatically.</p>



<a name="220721261"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220721261" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220721261">(Dec 22 2020 at 18:46)</a>:</h4>
<blockquote>
<p>Nothing to AST,</p>
</blockquote>
<p>I don't think it will ever be possible to use queries for macro expansion/name resolution due to it being a fixpoint algorithm. For parsing I don't think it is really beneficial either.</p>
<blockquote>
<p>AST to HIR,</p>
</blockquote>
<p>Same as for parsing I think.</p>
<blockquote>
<p>HIR to MIR,<br>
MIR to LLVM bitcode.</p>
</blockquote>
<p>Do you have any estimate about how much queries require HIR and can eagerly be invoked without having to wait till codegen?</p>



<a name="220724346"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220724346" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220724346">(Dec 22 2020 at 19:17)</a>:</h4>
<p>TBH, the stages were indicative. I don't know anything about what happens before lowering.</p>



<a name="220724552"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220724552" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220724552">(Dec 22 2020 at 19:19)</a>:</h4>
<p>I don't have stats, and I am not sure of how we should count. Quite a few queries are eagerly invoked in order to produce metadata. Among them: a lot of typing information + promoted &amp; optimized MIR.</p>



<a name="220724745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220724745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220724745">(Dec 22 2020 at 19:21)</a>:</h4>
<p>As a first step, I would like to create the split at MIR creation, so that everything that happens on MIR (borrow check &amp; optimisations) happens without the HIR.</p>



<a name="220724792"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220724792" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220724792">(Dec 22 2020 at 19:21)</a>:</h4>
<p>And thanks for creating the topic :)</p>



<a name="220725374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220725374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220725374">(Dec 22 2020 at 19:28)</a>:</h4>
<p>cc <span class="user-group-mention" data-user-group-id="3282">@wg-incr-comp</span></p>



<a name="220725836"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220725836" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220725836">(Dec 22 2020 at 19:32)</a>:</h4>
<p><span class="user-mention silent" data-user-id="248906">cjgillot</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Staged.20queries.20compiler-team.23391/near/220724346">said</a>:</p>
<blockquote>
<p>TBH, the stages were indicative. I don't know anything about what happens before lowering.</p>
</blockquote>
<p>FYI, we tried to write <a href="https://rustc-dev-guide.rust-lang.org/overview.html#what-the-compiler-does-to-your-code">a list of the different steps of compilation</a> in the rustc-dev-guide, but it's still got TODOs in unfortunate places</p>



<a name="220726522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220726522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220726522">(Dec 22 2020 at 19:40)</a>:</h4>
<p>I like the idea in principle, but I'm too big of a noob to comment on specifics. <span aria-label="big smile" class="emoji emoji-1f604" role="img" title="big smile">:big_smile:</span></p>
<p>I've had similar ideas while thinking of ways to reduce memory usage. In general, I think the idea of splitting compilation into a small set of well-defined stages, so that we can prune unnecessary data as we go along, could be profitable.</p>
<p>I kind of assumed that traditional compiler design used a more staged approach in this vein, and wondered if the query system intentionally avoided that approach to enable more flexibility. In any case, I assume there's a flexibility tradeoff here. Ideally, there are some very clear stages where we know we will never need any data that we've pruned at previous stage boundaries. Then flexibility wouldn't really be a concern.</p>
<p>Pruning could also be applicable beyond the query system. E.g. maybe it's possible to prune no-longer-useful interned / arena'd data. It's beyond the scope of the proposal, but it would be worth thinking about in advance, in case any mechanisms can be shared.</p>



<a name="220726612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220726612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220726612">(Dec 22 2020 at 19:41)</a>:</h4>
<p>the issue with a staged approach is it breaks incremental, it means you need to recalculate all the data even if you don't use it</p>



<a name="220726636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220726636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220726636">(Dec 22 2020 at 19:41)</a>:</h4>
<p>has anyone tried doing <code>drop(queries.hir().steal());</code> and seeing if that 'just works'?</p>



<a name="220726839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220726839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220726839">(Dec 22 2020 at 19:44)</a>:</h4>
<p>I guess you need somewhere to call it <em>from</em></p>



<a name="220731121"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220731121" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220731121">(Dec 22 2020 at 20:31)</a>:</h4>
<p>dropping the hir before codegen would require us to force all needed queries before then <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> I think changing <code>tcx.hir</code> to return <code>Steal</code> and then dropping it after mir building/analysis would be quite insightful and not too difficult hopefully</p>



<a name="220737514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220737514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220737514">(Dec 22 2020 at 21:47)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Staged.20queries.20compiler-team.23391/near/220726612">said</a>:</p>
<blockquote>
<p>the issue with a staged approach is it breaks incremental, it means you need to recalculate all the data even if you don't use it</p>
</blockquote>
<p>I am not so sure of that. By calling <code>ensure</code> on the output queries, we can avoid loading the data from the cache if its not used by later stages. Anyway, a lot of information is already forced for metadata output. I will aim at not forcing more queries manually.</p>



<a name="220737806"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220737806" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220737806">(Dec 22 2020 at 21:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="216206">lcnr</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Staged.20queries.20compiler-team.23391/near/220731121">said</a>:</p>
<blockquote>
<p>dropping the hir before codegen would require us to force all needed queries before then <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span> I think changing <code>tcx.hir</code> to return <code>Steal</code> and then dropping it after mir building/analysis would be quite insightful and not too difficult hopefully</p>
</blockquote>
<p>I tried to. I wanted to drop the HIR after all MIR is built. The trouble is that HIR data is appears in  a lot of queries. Furthermore, the <code>'tcx</code> lifetime is the one of the HIR (more precisely, of the arena which is declared in rustc_interface). Dropping this arena without having dangling pointers everywhere would require to drop a lot of query results.</p>
<p>About the point where the call to <code>steal</code> is done, it should be after having forced all the MIR to be built.</p>
<p>In summary, we get to this proposal.</p>



<a name="220738157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/220738157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#220738157">(Dec 22 2020 at 21:55)</a>:</h4>
<p>I thinl it should at least be possible to drop (or make empty) the hir::Crate without dropping the arena backing certain parts of the hir that can be borrowed.</p>



<a name="226005049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226005049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226005049">(Feb 11 2021 at 15:15)</a>:</h4>
<p>I'll have to read the backscroll, but I am mildly dubious of this -- part of our goal with the query system was to allow particular things to be compiled without forcing all things to be compiled</p>



<a name="226005170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226005170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226005170">(Feb 11 2021 at 15:15)</a>:</h4>
<p>Is there some place where ongoing design discussion is happening? (wg-incr-comp, maybe?)</p>



<a name="226005180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226005180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226005180">(Feb 11 2021 at 15:15)</a>:</h4>
<p>I mgiht be interested in joining some discussions on this topic</p>



<a name="226023885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226023885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226023885">(Feb 11 2021 at 17:07)</a>:</h4>
<p>There is no real discussion place about this. However, I am available in this thread.</p>



<a name="226025296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226025296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226025296">(Feb 11 2021 at 17:15)</a>:</h4>
<p>My initial consideration is the following: a few queries are forced for all definitions, to emit metadata. As a consequence, I wonder whether embedding this systematic forcing into the query system would allow "checkpoints" where we can clear the caches.</p>



<a name="226025477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226025477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226025477">(Feb 11 2021 at 17:16)</a>:</h4>
<p>For longer-term design, I started an incr-comp roadmap thread here, with an unsorted brain dump<br>
<a href="#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Roadmap.20and.20projects.20for.20incr-comp">https://rust-lang.zulipchat.com/#narrow/stream/241847-t-compiler.2Fwg-incr-comp/topic/Roadmap.20and.20projects.20for.20incr-comp</a></p>



<a name="226032082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226032082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> apiraino <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226032082">(Feb 11 2021 at 18:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Staged.20queries.20compiler-team.23391/near/226005170">said</a>:</p>
<blockquote>
<p>Is there some place where ongoing design discussion is happening? (wg-incr-comp, maybe?)</p>
</blockquote>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span>  I am currently revising the WG list on the <a href="https://rust-lang.github.io/compiler-team/">compiler team page</a> and just just noticed that @_<em>wg-incr-comp</em> has no page in that directory but has a Zulip presence under <a class="stream" data-stream-id="241847" href="/#narrow/stream/241847-t-compiler.2Fwg-incr-comp">#t-compiler/wg-incr-comp</a> and regular checkins at the compiler team meetings.<br>
So, worth adding some content for @_<em>wg-incr-comp</em> there, too?</p>



<a name="226035181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226035181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226035181">(Feb 11 2021 at 18:21)</a>:</h4>
<p>This was probably our (wg-incr-comp) fault. We can add a page there.</p>



<a name="226192021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226192021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226192021">(Feb 12 2021 at 20:29)</a>:</h4>
<p>Yes</p>



<a name="226192036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226192036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226192036">(Feb 12 2021 at 20:29)</a>:</h4>
<p>the list needs to be revisited</p>



<a name="226192053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226192053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226192053">(Feb 12 2021 at 20:29)</a>:</h4>
<p>perhaps the mechanism for maintaining it, too =)</p>



<a name="226192064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226192064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226192064">(Feb 12 2021 at 20:29)</a>:</h4>
<p>I feel like maybe it'd be better to move that list to the team repo</p>



<a name="226231697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226231697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226231697">(Feb 13 2021 at 07:16)</a>:</h4>
<p>Would it be possible to drop a hir::Body once the corresponding mir::Body is generated?</p>



<a name="226242096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/226242096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#226242096">(Feb 13 2021 at 12:06)</a>:</h4>
<p>if we wrap all <code>hir::Body</code>s in a <code>Steal</code>, this would work quite easily I would think</p>



<a name="232771159"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/232771159" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#232771159">(Apr 01 2021 at 15:00)</a>:</h4>
<p>Just a passing thought -- I'm wondering if we could avoid keeping all past queries in memory, e.g., with some kind of speculation/prediction/whatever</p>



<a name="233307604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233307604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233307604">(Apr 06 2021 at 12:13)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> in other words, determine what a good cache eviction strategy might be, and then impose an optional limit on the size of the query cache?</p>



<a name="233307678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233307678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233307678">(Apr 06 2021 at 12:14)</a>:</h4>
<p>yeah, we'd need to be careful around diagnostics/side-effects, but otherwise yes :)</p>



<a name="233307729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233307729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233307729">(Apr 06 2021 at 12:14)</a>:</h4>
<p>in theory you might even always want it, if you have sufficient fast cpu that fitting the query cache, in, say l3 is better for you</p>



<a name="233307841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233307841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233307841">(Apr 06 2021 at 12:15)</a>:</h4>
<p>maybe. Might depend on how much RAM you have, right?</p>



<a name="233307961"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233307961" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233307961">(Apr 06 2021 at 12:16)</a>:</h4>
<p>(i’m assuming this stuff will always tend to exhaust the L1/L2/L3 cache, at least…)</p>



<a name="233308296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233308296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233308296">(Apr 06 2021 at 12:19)</a>:</h4>
<p>yeah, maybe -- well, more so the RAM vs CPU speed; it might be faster in some cases to recompute the query, I guess, though it definitely depends on the query</p>



<a name="233308369"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233308369" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233308369">(Apr 06 2021 at 12:20)</a>:</h4>
<p>I know we had some which were like basically a hash table lookup, caching that in a hash table is 100% pointless and wasteful</p>



<a name="233312466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233312466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233312466">(Apr 06 2021 at 12:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116122">simulacrum</span> <a href="#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Staged.20queries.20compiler-team.23391/near/233308369">said</a>:</p>
<blockquote>
<p>I know we had some which were like basically a hash table lookup, caching that in a hash table is 100% pointless and wasteful</p>
</blockquote>
<p>Hmm. My first reaction was <span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span>. My second reaction was ”wait, that’s a different problem from cache eviction though, right? I.e., identifying cases that should never be cached at all?” My third reaction is now: “I guess there may be a spectrum here: Things that shoud never be cached, to things that may be useful to evict, and presumably there are things that, once computed, should never be evicted…"</p>



<a name="233313842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233313842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233313842">(Apr 06 2021 at 13:00)</a>:</h4>
<p>yeah, there's likely a spectrum. for some things a cache may make sense, but perhaps we do a bunch of queries on one thing and then never again. I don't know if we have hit rate metrics in a more granular (i.e. not overall hit rate, but per-element) way</p>



<a name="233321289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233321289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233321289">(Apr 06 2021 at 13:47)</a>:</h4>
<p>a per-element hit rate sounds like a good thing to capture. The evolution of the hit rate over time might also be useful.</p>



<a name="233359045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Staged%20queries%20compiler-team%23391/near/233359045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Staged.20queries.20compiler-team.23391.html#233359045">(Apr 06 2021 at 17:34)</a>:</h4>
<p>I guess there are actually two problems this proposal can address: (1) how to release memory for query results we do not need any more, and (2) how to convert between different representations of the crate.</p>
<p>On point 1, there can be many other answers. For instance, having a more systematic use of <code>Steal</code> along with caching just after the query computation (instead of at the end of compilations); having recomputable queries like <span class="user-mention silent" data-user-id="116122">simulacrum</span>  suggests... For now, the query system does not allow to recompute its results. Allowing that should be doable, but certainly very subtle to do efficiently (most notably: how to ensure the results are exactly the same without going through the full query code path?).</p>
<p>Point 2 is only interesting in the perspective of end-to-end queries. The most prominent issue here is iterating all LocalDefIds when queries can create new LocalDefIds. Having a staged query system could allow progress on incremental front-end (macro expansion and incremental parsing, if anybody actually wants make those incremental), while allowing for time to design and join everything cleanly.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>